package com.sharkburner.common.dao.paginator;

import java.util.List;

import org.hibernate.Query;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")
public class LazyQueryFactory implements LazyFactory {

    private Query queryList;
    private Query queryCount;
    private int size;

    @Override
    public int getSize() {
	return size;
    }

    @Override
    public List<Object> getList(int startIndex, int count) {
	queryList.setFirstResult(startIndex);
	queryList.setMaxResults(count);

	return queryList.list();
    }

    @Override
    public void setDataProvider(Object object) {
	queryList = (Query) object;
	queryCount = (Query) PaginationFactory.cloneDataProvider(object);

	size = 0;
    }

}
